package com.hong.concurrent.chapter11;

/**
 * @Author csh
 * @Description 使用线程保险箱实现上下文
 * @Date 2018/7/7 11:27
 */
public final class ActionContext {

    private static final ThreadLocal<Context> threadLocal = new ThreadLocal<Context>(){
        @Override
        protected Context initialValue() {
            return new Context();
        }
    };

    public ActionContext() {
    }

    private static class ContextHolder{
        private final static ActionContext actionContext = new ActionContext();
    }

    public static ActionContext getActionContext(){
        return ContextHolder.actionContext;
    }


    public Context getContext(){
        return threadLocal.get();
    }


}
